package com.waimai1.waimai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.waimai1.waimai.dao.HwMovieCityDao;
import com.waimai1.waimai.entity.HwMovieCity;
import com.waimai1.waimai.service.HwMovieCityService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (HwMovieCity)表服务实现类
 *
 * @author makejava
 * @since 2023-09-09 19:27:05
 */
@Service
public class HwMovieCityServiceImpl extends ServiceImpl<HwMovieCityDao, HwMovieCity> implements HwMovieCityService {

    public void updateCity(Map<String,Object> info) {
        List dataList=new ArrayList<HashMap>();
        dataList=(ArrayList<HashMap>) info.get("data");
        List<HwMovieCity> resultList=new ArrayList<>();

        for(Object item:dataList){
            HashMap<String,Object> tempMap=(HashMap<String,Object>)item;
            String cityName=tempMap.get("cityName").toString();
            String cityId=tempMap.get("cityId").toString();
            List regionList=(ArrayList<HashMap>) tempMap.get("regions");
            for(Object regionItem:regionList){
                HwMovieCity hwMovieCity=new HwMovieCity();
                HashMap<String,Object> tempRegionMap=new HashMap<String,Object>();
                tempRegionMap=(HashMap<String,Object>)regionItem;
                hwMovieCity.setCityRegion(cityName+"-"+tempRegionMap.get("regionName").toString());
                hwMovieCity.setCityRegionId(cityId+"-"+tempRegionMap.get("regionId").toString());
                resultList.add(hwMovieCity);
            }
        }
        this.saveBatch(resultList);
    }
}

